package com.znjb.myapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.znjb.myapplication.R;

import java.util.List;

/**
 * Created by 刘亚飞 on 2017/3/16.
 */

public class MyGridVIewAdapter extends BaseAdapter {
    private List<String> datas;
    private Context context;
    private int tempClick = -1;

    public MyGridVIewAdapter(Context context) {
        this.context = context;
    }

    public void setDatas(List<String> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    public void setSelection(int position){
        tempClick = position;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int i) {
        return datas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.grid_item,viewGroup,false);
            holder = new ViewHolder();
            holder.tv = (TextView) view.findViewById(R.id.tv);
            view.setTag(holder);
        }else {
            holder = (ViewHolder) view.getTag();
        }

        holder.tv.setText(datas.get(i));

        return view;
    }


    class ViewHolder{
        TextView tv;
    }
}
